var vm = new Vue({
	el: '#app',
	data() {
	  return {
		tableData: null,
		userQuery: {
			name:"",
			begin:"",
			end:""
		},
		page:1, //当前页
	    limit:10, //每页记录数
	    total:0,
	  }
	},
	created() {
		this.userInfo()
	},
	methods: {
		//刷新按钮
		flush:function(){
			this.userQuery={
				name:"",
				begin:"",
				end:""
			}
			this.userInfo();
		},
		//序号
		indexMethod(index) {
		    return index + 1;
		},
		userInfo: function (val) {
			console.log('当前页：',val)
			var that = this;
			that.page=val;
			
			$.ajax({
				url: gateway + '/admin/user/findAll',
				type:'get', //GET
				async:false,    //或false,是否异步
				data:{
					"page":this.page,
					"size":this.limit,
					"name":this.userQuery.name,
					"begin":this.userQuery.begin,
					"end":this.userQuery.end
				},
				timeout:5000,    //超时时间
				dataType:'json',    //返回的数据格式：json/xml/html/script/jsonp/text
				beforeSend: function(xhr) {
					/*console.log(xhr)
					 console.log('发送前')*/
				},
				success: function(res) {
					console.log(res)
					that.tableData = res.data.list;
					that.total = res.data.totalRows;
					// console.log(that.tableData[1].locked)
					
				},
				error: function(xhr, textStatus) {
					console.log('错误')
				},
			});
		 //    this.$http.get(gateway+'/admin/user/findAll',{"page":this.page,
			// "size":this.limit,"name":this.userQuery.name})
			// .then(function(res){
			// 	console.log(res)
		 //        this.tableData = res.body.data.list;
			// 	this.total = res.body.data.totalRows;
		 //        console.log(this.tableData[1].locked)
		 //    },function(){
		 //        console.log('err');
		 //    });
		},
		//删除用户
		removeDataById(id){
			var that = this;
			this.$confirm('确定要删除此用户','提示', {
				confirmButtonText: '确定',
				cancelButtonText: '取消',
				type: 'warning'
			}).then(() => { //成功回调
				$.ajax({
					url: gateway + '/admin/user/delete/'+id,
					type:'get', //GET
					async:false,    //或false,是否异步
					timeout:5000,    //超时时间
					dataType:'json',    //返回的数据格式：json/xml/html/script/jsonp/text
					beforeSend: function(xhr) {
						/*console.log(xhr)
						 console.log('发送前')*/
					},
					success: function(res) {
						console.log(res)
						that.userInfo()	
					},
					error: function(xhr, textStatus) {
						console.log('err');
					},
				});
			});
			return;
			
		},
		//修改
		updateUserById(id){
			window.location.href = "userSave.html?id="+id;
		},
		//添加
		handleadd:function(id){
			window.location.href = "userSave.html?id="+id;
		},
		goBack(){
		        window.history.go(-1); 
		      },
	}
})
